﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.BLL;
using YouHP.Utility;
using YouHP.Model;
using System.Text.RegularExpressions;
using System.Web;

namespace YouHP.Pages.User
{
    public class NewLogCommentList : UserBasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();
            if (this.ErrorCount > 0) return;

            HandleCommon();
            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected List<LogCommentInfo> LogCommentDataList;
        protected int PageIndex;
        protected int PageSize = 20;
        protected int DataCount;
        protected int PageCount;
        protected string PagingString = "";

        protected void HandleCommon()
        {
            this.SetTitle("日志评论");
            this.AddLocation("日志评论", "");
            this.AddLinkCss("/support/alpha/css/NewLogCommentList.css");
            this.AddScriptSrc("/support/Alpha/Js/mootools.js");

            //更新未读日志评论的状态为已读
            LogCommentBLL.Instance.UpdateLogCommentStateByUserId(UserData.Id,0);
            this.GetMsgCount();

        }
        protected void HandlePost()
        {
            int lid = RequestTools.GetFormInt("logId", -1);
            int logCommentId = RequestTools.GetFormInt("logCommentId", -1);

            bool succ = LogCommentBLL.Instance.DeleteLogComment(lid, logCommentId);
            if (succ)
            {
                this.Redirect("/User/NewLogCommentList.aspx");
            }
            else
            {
                this.AddErrLine("系统操作失败！");
                return;
            }
        }

        protected void HandleGet()
        {
            PageIndex = RequestTools.GetQueryInt("page", 1);

            LogCommentDataList = LogCommentBLL.Instance.GetLogCommentListByUserId(PageSize, PageIndex, UserData.Id, out DataCount);
            PageCount = Utils.GetPageCount(DataCount, PageSize);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            PagingString = this.GetPagingString(
                PageIndex,
                PageCount,
                "/User/NewLogCommentList.aspx" + query, "page");
        }
    }
}